
let View = require("View")

class HomeView extends View
{
    open(finishCallback)
    {
        let user = require('UserSystem').share().hostUser()
        this.mUser = user

        const User_base = require('User_base')

        let root = this.widget('1')
        
        // let node = this.widget('name', root).getComponent(cc.Label)
        // node.string = "" + user.contentBy(User_base.name)


        this.startUpdate(
            (dt)=>{

                // ui login fps call

                // if (tim >= 0)
                // {
                //     tim += dt

                //     if (tim > 1.6)
                //     {
                //         tim = -1

                //         let vm = require("ViewMan").share()
                //         vm.pop(this)
                //     }
                // }
            }
        )

        finishCallback && finishCallback()
    }
    
    quit()
    {
        this.mUser     = null

        let as = require('AudioSystem').share()
        as.stop()
    }

    onEvent(e)
    {
        const Evts = require('Evts')
        
        if (e.type == Evts.USER_DIRTY)
        {
            if (e.data)
            {
                const User_base = require('User_base')
                
                if (e.data.gd)
                {
                    this.find('gold.1').getComponent(cc.Label).string = '' + require('Number').kmb(this.mUser.contentBy(User_base.gold))
                }

                if (e.data.gm)
                {
                    this.find('gem.1').getComponent(cc.Label).string = "" + this.mUser.contentBy(User_base.gem)
                }
            }
        }
    }
}

export default HomeView
